(function(scope){
/*	
	# 	PI JAVASCRIPT LIBRARY (FULL&UNCOMPRESSED VERSION)
	#	
	#	VERSION HISTORY:
	#	-> V1 Alpha						21.03.2008 01:18
	#	-> V0.1 Alpha-Comet Version 	11.03.2008 21:47	
	#
	#	DEVELOPMENT
	#	Azer Koçulu <http://azer.kodfabrik.com>
	#	http://pi-js.googlecode.com
*/	
	
	scope.pi = Object(3.14159265358979323846), scope=scope.pi;
	
	/*
	 * pi.env
	 * environment variables
	 */
	scope.env = {
		// browser detection
		ie: /MSIE/i.test(navigator.userAgent),
		ie6: /MSIE 6/i.test(navigator.userAgent),
		ie7: /MSIE 7/i.test(navigator.userAgent),
		ie8: /MSIE 8/i.test(navigator.userAgent),
		firefox: /Firefox/i.test(navigator.userAgent),
		opera: /Opera/i.test(navigator.userAgent),
		webkit: /Webkit/i.test(navigator.userAgent),
		// 
		getWindowSize:function(){
			return {
				height:scope.env.ie?Math.max(document.documentElement.clientHeight,document.body.clientHeight):window.innerHeight,
				width:scope.env.ie?Math.max(document.documentElement.clientWidth,document.body.clientWidth):window.innerWidth
			}
		},
		//
		DOMContentLoaded:function(){
			if(!scope.env.ie)
				document.removeEventListener("DOMContentLoaded",scope.env.DOMContentLoaded,false);
			else
				window.detachEvent("onload",scope.env.DOMContentLoaded);
			if(!scope.env.DOMContentLoaded.init)return;
			scope.env.DOMContentLoaded.init();
		},
		// event shortcuts
		addEvent: function(ELEMENT,EVENT_NAME,FN,USE_CAPTURE_OPTION){
			return ELEMENT[scope.env.ie?"attachEvent":"addEventListener"]((scope.env.ie?"on":"")+EVENT_NAME,FN,Boolean(USE_CAPTURE_OPTION));
		},
		removeEvent: function(ELEMENT,EVENT_NAME,FN,USE_CAPTURE_OPTION){
			return ELEMENT[scope.env.ie?"detachEvent":"removeEventListener"]((scope.env.ie?"on":"")+EVENT_NAME,FN,Boolean(USE_CAPTURE_OPTION));
		}
	};
	if(!scope.env.ie)
		document.addEventListener("DOMContentLoaded",scope.env.DOMContentLoaded,false);
	else
		window.attachEvent("onload",scope.env.DOMContentLoaded);
	
	/*
	 * pi.get
	 * element selector
	 */
	scope.get = function(){
		return document.getElementById.apply(document,arguments);
	};
	scope.get.tag = function(){
		return document.getElementsByTagName.apply(document,arguments);
	};
	scope.get.className = document.getElementsByClassName?
		function(){
			return document.getElementsByClassName.apply(document,arguments);
		}:function(className){
			return this.query(false,"class",className);
		};
	scope.get.query = function(TAG,ATTRIBUTE,ATTRIBUTE_VALUE){
		evaluation = scope.xpath(
			"/{0}{1}".format( (TAG?"/{0}".format(TAG):"/*"), "[contains(concat(' ', @{0}, ' '),' {1} ')]".format(ATTRIBUTE,ATTRIBUTE_VALUE) ),
			"ORDERED_NODE_SNAPSHOT_TYPE"
		);
		
		return evaluation.snapshotLength.range(function(rangeIterator){
			return evaluation.snapshotItem(rangeIterator);
		});
	};
	
	/*
	 * pi.base
	 * base class
	 */
	scope.base = function(){
		this.body = {};
	};
	
	scope.base.prototype = {
		"build":function(){
			var parent = this;
			var fn = function(){
				for (key in this) {
					if (this[key] instanceof Array) 
						this[key] = this[key].clone();
					else if (typeof this[key] == "object" && typeof !this[key].nodeName) {
							this[key]._parent_ = this;
							this[key] = scope.dict.prototype._clone_.apply(this[key], [true]);
						}
				}
				if(parent.constructor!=null)
					parent.constructor.apply(this,arguments);
			};
			
			for (key in this.body) {
				if (this.body[key] instanceof Object && typeof this.body[key] == "object" && !this.nodeType){
					for (key_ in this.body[key]) {
						if (key_.substring(0, 1) != "_") 
							continue;
						var name = key_, title = name.substring(1, 2).toUpperCase() + name.substring(2);
						
						if (Boolean(this.body[key]["get" + title]) == false) 
							this.body[key]["get" + title] = new Function("return this." + name);
						if (Boolean(this.body[key]["set" + title]) == false) 
							this.body[key]["set" + title] = new Function("VALUE", "this." + name + " = VALUE;");
					}
				}
			};
			
			
			fn.prototype = this.body;
			return fn;
		},
		"constructor":null,
		"extend":function(OBJECT){
			this.body = pi.dict.prototype._clone_.apply(OBJECT.prototype);
			return this;
		}
	};
	
	/*
	 * pi.comet
	 */
	scope.comet = new scope.base;
	scope.comet.constructor = function(){
		this.environment.setName("piComet");
		this.environment.setType(scope.env.ie?3:scope.env.opera?2:1);
		this.environment.setTunnel(
			this.environment.getType()==3?new ActiveXObject("htmlfile"):
			this.environment.getType()==2?document.createElement("event-source"):
			new scope.xhr
		);
	};
	scope.comet.body = {
		"abort":function(){
			switch(this.environment.getType()){
				case 1:
					this.environment.getTunnel().abort();
					break;
				case 2:
					document.body.removeChild(this.environment.getTunnel());
					break;
				case 3:
					this.environment.getTunnel().body.innerHTML="<iframe src='about:blank'></iframe>";
			}
		},
		"send":function(){
			switch(this.environment.getType()){
				case 1:
					this.environment.getTunnel().send();
					break;
				case 2:
					document.body.appendChild(this.environment.getTunnel());
					this.environment.getTunnel().addEventListener(this.environment.getName(),this.event.change,false);
					break;
				case 3:
					this.environment.getTunnel().open();
					this.environment.getTunnel().write("<html><body></body></html>");
					this.environment.getTunnel().close();
					this.environment.getTunnel().parentWindow._cometObject = this;
					this.environment.getTunnel().body.innerHTML="<iframe src='{0}'></iframe>".format(this.environment.getUrl());
			}
		}
	};
	scope.comet.body.environment = {
		"_name":"", "_tunnel":null, "_type":"", "_url":"",
		"setTunnel":function(VALUE){
			if(this.getType()==1){
				VALUE.environment.addData("cometType","1");
				VALUE.environment.addCallback(this._parent_.event.change,3);
				VALUE.environment.setCache(false);
			}
			
			VALUE._cometApi_ = this._parent_;
			this._tunnel = VALUE;
		},
		"setUrl":function(VALUE){
			if(this.getType()>1)
			{
				VALUE = "{0}{1}cometType={2}&cometName={3}".format(VALUE,VALUE.search("\\?")>-1?"&":"?",this.getType(),this.getName());
				
				if(this.getType()==2)
					this.getTunnel().setAttribute("src",VALUE);
			} else
				this.getTunnel().environment.setUrl(VALUE);
			
			this._url = VALUE;
		}
	};
	scope.comet.body.event = {
		"change":function(){
			var response = null;
			if(this._cometApi_.environment.getType()==2)
				response = arguments[0].data;
			else {
				response = this.environment.getApi().responseText.split("<end />");
				response = response[response.length-1];
			}
   			this._cometApi_.event.push(response);
		},
		"push":function(TEXT){}
	};
	scope.comet = scope.comet.build();
	
	/*
	 * pi.dict
	 * dictionary object
	 */
	
	scope.dict = new scope.base;
	scope.dict.constructor = function(OBJECT){
		OBJECT = OBJECT||{};
		for(key in OBJECT){
			this._environment_.appendKey(key);
			this._environment_.appendValue(OBJECT[key]);
			this._environment_.getObject()[key]=OBJECT[key];
			this[key] = OBJECT[key];
		}
	};
	scope.dict.body = {
		"_append_":function(KEY,VALUE){
			this._environment_.appendKey(KEY);
			this._environment_.appendValue(VALUE);
			this._environment_.getObject()[KEY] = VALUE;
			this[KEY] = VALUE;
		},
		"_clone_":function(INCLUDE_PRIVATE_MEMBERS_OPTION){
			var tmp = {};
			for(key in this)
			{
				if(Boolean(INCLUDE_PRIVATE_MEMBERS_OPTION)==false&&this._clone_&&key.substring(0,1)+key.substring(key.length-1)=="__")continue;
				tmp[key] = (typeof this[key]=="object"&&key!="_parent_"&&this[key]!=null&&!this[key].nodeName)?
								(	this[key] instanceof Array?
									this[key].clone():
						 	  		scope.dict.prototype._clone_.apply(this[key],arguments)
								):this[key];
			}
			return tmp;
		},
		"_get_":function(INDEX){
			return [this._environment_.getKey()[INDEX],this._environment_.getValue()[INDEX]];
		},
		"_length_":function(){
			return this._environment_.getKey().length;
		},
		"_remove_":function(KEY){
			var arrayIndex = this._environment_._key.indexOf(KEY);
			this._environment_.setKey(this._environment_._key.remove(arrayIndex));
			this._environment_.setValue(this._environment_._value.remove(arrayIndex));
			delete this._environment_.getObject()[KEY];
			delete this[KEY];
		}
	};
	scope.dict.body._environment_ = {
		"_key":[], "_object":{}, "_value":[],
		"appendKey":function(VALUE){
			this._key.push(VALUE);
			return this._key;
		},
		"hasKey":function(KEY){
			return Boolean(this.getObject()[KEY])
		},
		"appendValue":function(VALUE){
			this._value.push(VALUE);
			return this._value;
		},
		"hasValue":function(VALUE){
			return Boolean(this.getValue().indexOf(VALUE)>-1)
		}
	};

	scope.dict = scope.dict.build();
	
	/*
	 * pi.element
	 */
	
	scope.element = new scope.base;
	scope.element.constructor = function(TAG_NAME){
		this.environment.setElement(document.createElement(TAG_NAME||"div"));
		return this;
	};
	scope.element.body = {
		"clean":function(){
			var childs = this.child.get();
			while(childs.length){
				childs[0].parentNode.removeChild(childs[0]);
			}
		},
		"clone":function(DEEP_OPTION){
			return this.environment.getElement().cloneNode(DEEP_OPTION);
		},
		"insert":function(ELEMENT){
			ELEMENT = ELEMENT.environment?ELEMENT.environment.getElement():ELEMENT;
			ELEMENT.appendChild(this.environment.getElement());
			return this;
		},
		"insertAfter":function(REFERENCE_ELEMENT){
			REFERENCE_ELEMENT.nextSibling?this.insertBefore(REFERENCE_ELEMENT.nextSibling):this.insert(REFERENCE_ELEMENT.parentNode);
			return this;
		},
		"insertBefore":function(REFERENCE_ELEMENT){
			REFERENCE_ELEMENT = REFERENCE_ELEMENT.environment?REFERENCE_ELEMENT.environment.getElement():REFERENCE_ELEMENT;
			REFERENCE_ELEMENT.parentNode.insertBefore(this.environment.getElement(),REFERENCE_ELEMENT);
			return this;
		},
		"query":function(EXPRESSION,RESULT_TYPE,NAMESPACE_RESOLVER,RESULT){
			return scope.xpath(EXPRESSION,RESULT_TYPE||"ORDERED_NODE_SNAPSHOT_TYPE",this.environment.getElement(),NAMESPACE_RESOLVER,RESULT);
		},
		"remove":function(){
			this.environment.getParent().removeChild(
				this.environment.getElement()
			);
		},
		"update":function(VALUE){
				(["TEXTAREA","INPUT"].indexOf(this.environment.getName())>-1)?
				(this.environment.getElement().value = VALUE):
				(this.environment.getElement().innerHTML = VALUE);
				
				return this;
		}
	};

	scope.element.body.attribute = {
		"getAll":function(NAME){
			return this._parent_.environment.getElement().attributes;
		},
		"clear":function(NAME){
			this.set(NAME,"");
			return this._parent_;
		},
		"get":function(NAME){
			return this._parent_.environment.getElement().getAttribute(NAME);
		},
		"has":function(NAME){
			return scope.env.ie?(this.get(NAME)!=null):this._parent_.environment.getElement().hasAttribute(NAME);
		},
		"remove":function(NAME){
			this._parent_.environment.getElement().removeAttribute(NAME);
			return this._parent_;
		},
		"set":function(NAME,VALUE){
			this._parent_.environment.getElement().setAttribute(NAME,VALUE);
			return this._parent_;
		},
		"addClass":function(CLASS){
			if(this.hasClass(CLASS))return false;
			this.setClass("{0} {1}".format(this.getClass(),CLASS));
			return this._parent_;
		},
		"clearClass":function(){
			this.setClass("");
			this._parent_;
		},
		"getClass":function(){
			var currentClass = this.get(scope.env.ie?"className":"class");
			return currentClass?currentClass:"";
		},
		"hasClass":function(CLASS){
			return this.getClass().split(" ").count(CLASS)>0;
		},
		"setClass":function(VALUE){
			return this.set(scope.env.ie?"className":"class",VALUE);
		},
		"removeClass":function(CLASS){
			if(this.hasClass(CLASS))
				this.setClass(this.getClass().split(" ").removeValue(CLASS).join(" "));
			return this._parent_;
		},
		"toggleClass":function(CLASS){
			if(this.hasClass(CLASS))
				this.removeClass(CLASS);
			else
				this.addClass(CLASS);
			return this._parent_;
		}
	};
	scope.element.body.child = {
		"get":function(){
			return this._parent_.environment.getElement().childNodes;
		},
		"add":function(ELEMENT){
			this._parent_.environment.getElement().appendChild(
				ELEMENT.environment?ELEMENT.environment.getElement():ELEMENT
			);
			return this._parent_;
		},
		"addAfter":function(ELEMENT,REFERENCE_ELEMENT){
			this.addBefore(ELEMENT,REFERENCE_ELEMENT.nextSibling);
			return this._parent_;
		},
		"addBefore":function(ELEMENT,REFERENCE_ELEMENT){
			this._parent_.environment.getElement().insertBefore(
				ELEMENT.environment?ELEMENT.environment.getElement():ELEMENT,
				REFERENCE_ELEMENT
			);
			return this._parent_;
		},
		"query":function(TAG,ATTRIBUTE_NAME,ATTRIBUTE_VALUE){
			var query = "{0}{1}".format( (TAG?"{0}".format(TAG):"/*"), ATTRIBUTE_NAME||ATTRIBUTE_VALUE?"[contains(concat(' ', @{0}, ' '),' {1} ')]".format(ATTRIBUTE_NAME||"",ATTRIBUTE_VALUE||""):"" );
			return this._parent_.query(query);
		},
		"remove":function(ELEMENT){
			this._parent_.environment.getElement().removeChild(ELEMENT);
		}
	};
	scope.element.body.environment = {
		"_element":null, "_view":null,
		"setElement":function(VALUE){
			VALUE.pi = this._parent_;
			this._element = VALUE;
			return this._parent_;
		},
		"getOpacity":function(STYLE_OBJECT_OPTION){
			var styleObject = STYLE_OBJECT_OPTION||this.getView();
			if(!this.env.ie)
				return styleObject["opacity"];
				
			var alpha = styleObject["filter"].match(/opacity\=(\d+)/i);
			return alpha?alpha[1]/100:1;
		},
		"setOpacity":function(VALUE){
			if(!scope.env.ie)
				return this.setStyle({ "opacity":VALUE });
			
			VALUE*=100;
			this.addStyle({ "filter":"alpha(opacity="+VALUE+")" });
			return this._parent_;
		},
		"getParent":function(){
			return this.getElement().parentNode;
		},
		"getPosition":function(){
			var parent = this.getElement();
			var offsetLeft = 0;
			var offsetTop = 0;
			while(parent&&parent!=document.body&&parent!=document.firstChild){
				offsetLeft +=parseInt(parent.offsetLeft);
				offsetTop += parseInt(parent.offsetTop);
				parent = parent.offsetParent;
			}
			
			return {
				"bottom":this.getView()["bottom"],
				"left":this.getView()["left"],
				"offsetLeft":offsetLeft,
				"offsetTop":offsetTop,
				"position":this.getView()["position"],
				"right":this.getView()["right"],
				"top":this.getView()["top"],
				"z-index":this.getView()["zIndex"]
			};
		},
		"getSize":function(){
			return {
				"height":this.getView()["height"],
				"offsetHeight":this.getElement().offsetHeight,
				"offsetWidth":this.getElement().offsetWidth,
				"width":this.getView()["width"]
			}
		},
		"addStyle":function(VALUE){
			for(var i=new scope.iterator(VALUE); !i.atEnd;){
				var item = i.next();
				item[0] = item[0]=="float"?(scope.env.ie?"styleFloat":"cssFloat"):item[0];
				if (item[0] == "opacity" && scope.env.ie) {
					this.setOpacity(item[1]);
					continue;
				}
				this.getElement().style[item[0]] = item[1];
			}
			return this._parent_;
		},
		"getStyle":function(PROPERTY_OPTION){
			PROPERTY_OPTION = PROPERTY_OPTION=="float"?(scope.env.ie?"styleFloat":"cssFloat"):PROPERTY_OPTION;
			if(PROPERTY_OPTION=="opacity"&&scope.env.ie)
				return this.getOpacity(this.getElement().style);
			return typeof PROPERTY_OPTION=="string"?this.getElement().style[PROPERTY_OPTION]:this.getElement().style;
		},
		"getName":function(){
			return this.getElement().nodeName;
		},
		"getType":function(){
			return this.getElement().nodeType;
		},
		"getView":function(PROPERTY_OPTION){
			if(this._view==null){
				this.setView(document.defaultView?document.defaultView.getComputedStyle(this.getElement(),null):this.getElement().currentStyle);
			}
			PROPERTY_OPTION = PROPERTY_OPTION=="float"?(scope.env.ie?"styleFloat":"cssFloat"):PROPERTY_OPTION;
			if(PROPERTY_OPTION=="opacity"&&scope.env.ie)
				return this.getOpacity();
			return typeof PROPERTY_OPTION=="string"?this._view[PROPERTY_OPTION]:this._view;
		}
	};
	scope.element.body.event = {
		"addListener":function(EVENT_NAME,FN,USE_CAPTURE_OPTION){
			scope.env.addEvent(this._parent_.environment.getElement(),EVENT_NAME,FN,USE_CAPTURE_OPTION);
			return this._parent_;
		},
		"removeListener":function(EVENT_NAME,FN,USE_CAPTURE_OPTION){
			scope.env.removeEvent(this._parent_.environment.getElement(),EVENT_NAME,FN,USE_CAPTURE_OPTION);
			return this._parent_;
		}
	};
	scope.element = scope.element.build();
	
	/*
	 * pi.iterator
	 */
	
	scope.iterator = new scope.base;
	scope.iterator.constructor = function(OBJECT,TYPE_OPTION){
		/*
		 * OBJECT TYPES:
		 * 0: Any
		 * 1: Array
		 * 2: Object
		 * 99: pi.dict
		 * 98: XPathResult
		 */
		this.environment.setType(
			TYPE_OPTION||(OBJECT instanceof Array||(typeof NodeList!="undefined"&&OBJECT instanceof NodeList)||(typeof OBJECT=="object"&&OBJECT!=null&&OBJECT.length&&OBJECT.item)?1:
			OBJECT instanceof XPathResult?98:
			typeof OBJECT=="object" && !OBJECT.nodeName?(OBJECT._clone_?99:2):
			0)
		);
		this.environment.setObject(OBJECT);
		this.atEnd = this.environment.getLength()==0;
	};
	scope.iterator.body = {
		"next":function(){
			this.environment._index++;
			this.atEnd = this.environment.getLength()==this.environment.getIndex()+1;
			return this.environment.getItem(this.environment.getIndex());
		}
	};
	scope.iterator.body.environment = {
		 "_array":null, "_dict":null, "_index":-1, "_length":0, "_node":null, "_object":null, "_type":0, "_xPathResult":null,
		 "getItem":function(INDEX){
		 	if(this.getType()<3)
				return this.getArray()[INDEX];
			switch(this.getType()){
				case 99:
					return this.getDict()._get_(INDEX);
				case 98:
					return this.getXPathResult().snapshotItem(INDEX);
			}
		 },
		 "setObject":function(VALUE){
		 	this["_"+({"0":"node","1":"array","2":"object","99":"dict","98":"xPathResult"}[this.getType()])] = VALUE;
			
			switch(this.getType()){
				case 0:
					this.setArray([this.getNode()]);
					this.setLength(1);
					break;
				case 1:
					this.setLength(this.getArray().length);
					break;
				case 2:
					this.setArray([]);
					for (key in this.getObject()) {
						try {
							this.getArray().push([key, this.getObject()[key]]);
						}catch(e){}
					}
					this.setLength(this.getArray().length);
					break;
				case 99:
					this.setLength(this.getDict()._length_());
					break;
				case 98:
					if(this.getXPathResult().resultType<6){
						this.setType(1);
						break;
					}
					this.setLength(this.getXPathResult().snapshotLength);
					break;
			}
			
		 }
	};
	scope.iterator = scope.iterator.build();
	
	/*
	 * pi.xhr
	 * xmlhttprequest
	 */
	scope.xhr = new scope.base;
	scope.xhr.constructor = function(){
		var api = window.XMLHttpRequest?XMLHttpRequest:ActiveXObject("Microsoft.XMLHTTP");
		this.environment.setApi(
			new api()
		);
		this.environment.getApi().onreadystatechange=this.event.readystatechange.curry(this);
		this.environment.getApi().onerror=this.event.error.curry(this);
	};
	scope.xhr.body = {
		"abort":function(){
			this.environment.getApi().abort();
		},
		"send":function(){
			var url = this.environment.getUrl(), data = this.environment.getData(),dataUrl = ""; 

			for (key in data)
				dataUrl += "{0}={1}&".format(key, data[key]);
				
			if (this.environment.getType()=="GET"&&url.search("\\?") == -1)
				url += "?{0}".format(dataUrl);
			
			this.environment.getApi().open(this.environment.getType(),url,this.environment.getAsync());
			
			for(key in this.environment.getHeader())
				this.environment.getApi().setRequestHeader(key,this.environment.getHeader()[key]);

			this.environment.getApi().send(this.environment.getType()=="GET"?"":dataUrl);
		}
	},
	scope.xhr.body.environment = {
		"_async":true, "_api":null, "_cache":true, "_callback":[], "_channel":null, "_data":{}, "_header":{}, "_mimeType":null, "_multipart":false, "_type":"GET", "_timeout":0, "_url":"",
		"addCallback": function(FUNCTION,READYSTATE_VALUE,STATUS_VALUE){
			this.getCallback().push({ "fn":FUNCTION, "readyState":READYSTATE_VALUE||4, "status":STATUS_VALUE||200  });
		},
		"addHeader": function(KEY,VALUE){
			this.getHeader()[KEY] = VALUE;
		},
		"addData": function(KEY,VALUE){
			this.getData()[KEY] = VALUE;
		},
		"setCache":function(VALUE){
			if(VALUE==false){
				this.addData("forceCache",Math.round(Math.random()*10000));
			}
			this._cache = VALUE;
		},
		"setType": function(VALUE){
			if(VALUE=="POST"){
				this.addHeader("Content-Type","application/x-www-form-urlencoded");
			}
			this._type = VALUE;
		}
	};
	scope.xhr.body.event = {
		"readystatechange":function(){
			var readyState = this.environment.getApi().readyState;
			var callback=this.environment.getCallback();

			for (var i = 0; i < callback.length; i++) {
				if (callback[i].readyState==readyState) 
					 callback[i].fn.apply(this);
			}
		},
		"error":function(){
		}
	};
	scope.xhr = scope.xhr.build();
	
	/*
	 * pi.xpath
	 */
	
	scope.xpath = function(EXPRESSION,RESULT_TYPE,CONTEXT_NODE,NAMESPACE_RESOLVER,RESULT){
		var contextNode = CONTEXT_NODE||document, 
		expression = EXPRESSION||"",
		namespaceResolver = NAMESPACE_RESOLVER||null, 
		result=RESULT||null,
		resultType=RESULT_TYPE||"ANY_TYPE";
		return document.evaluate(expression, contextNode, namespaceResolver, XPathResult[resultType], result);
	};
	
	/*
	 * array
	 */
	Array.prototype.clone = function(){
		var tmp = [];
		Array.prototype.push.apply(tmp,this);
		tmp.forEach(function(item,index,object){
			if(item instanceof Array)
	    		object[index] = object[index].clone();
		});
		
	    return tmp;
	};
	Array.prototype.count = function(VALUE){
		var count = 0;
		this.forEach(function(){
			count+=Number(arguments[0]==VALUE);
		});
		return count;
	};
	
	if(Boolean(Array.prototype.forEach)==false)
	Array.prototype.forEach = function(FUNCTION){
		for(var i=0; i<this.length; i++)
			FUNCTION.apply(this,[this[i],i,this]);
			
	};
	
	Array.prototype.getLastItem = function(){
		return this[this.length-1];
	};
	
	if(Boolean(Array.prototype.indexOf)==false)
	Array.prototype.indexOf = function(VALUE){
		var index = -1;
		for(var i=0; i<this.length; i++)
			if(this[i]==VALUE){
				index = i;
				break;
			}
		return index;
	};
	
	Array.prototype.remove = function(INDEX){
		var array = this.slice(0,INDEX);
		Array.prototype.push.apply(array,this.slice(INDEX+1));
		return array;
	};
	
	Array.prototype.removeValue = function(VALUE){
		return this.remove(this.indexOf(VALUE));
	};
	
	/*
	 * boolean
	 */
	Boolean.prototype.toggle = function(){
		return this==true?arguments[0]:arguments[1];
	};
	
	/*
	 * function
	 */
	Function.prototype.curry = function(SCOPE){
		var fn = this;
		var scope = SCOPE||window;
		var args = Array.prototype.slice.call(arguments,1);
		return function(){ 
			args.push.apply(args,Array.prototype.slice.call(arguments,0));
			return fn.apply(scope,args); 
		};
	};
	
	Function.prototype._doc_ = "Null.";

	/*
	 * number
	 */
	Number.prototype.base = function(SYSTEM){
		var remain = this%SYSTEM;
		if(this==remain)return String.fromCharCode(this+(this>9?87:48));
		return ((this-remain)/SYSTEM).base(SYSTEM)+String.fromCharCode(remain+(remain>9?87:48));
	};
	Number.prototype.decimal = function(SYSTEM){
		var result = 0, digit = String(this).split("");
		for(var i=0; i<digit.length; i++)
		{
			digit[i]=parseInt((digit[i].charCodeAt(0)>58)?digit[i].charCodeAt(0)-87:digit[i]);
			result += digit[i]*(Math.pow(SYSTEM,digit.length-1-i));
		}
		return result;
	};
	Number.prototype.range = function(PATTERN){
		for(
			var value = String(this), isFloat = /\./i.test(value), 
			i = isFloat.toggle(parseInt(value.split(".")[0]),0), 
			end = parseInt(value.split(".")[isFloat.toggle(1,0)]), 
			array = []; i<end; i++
		){
			array.push(
				Boolean(PATTERN)==false?i:(typeof PATTERN=="function"?PATTERN(i):PATTERN[i])
			);
		}
		return array;
	};

	/*
	 * string
	 */
	String.prototype.escape = function(){
		return escape(this);
	};

	String.prototype.format = function(){
		var values = arguments;
		return this.replace(/\{(\d)\}/g,function(){
			return values[arguments[1]];
		})
	};
	
	String.prototype.leftpad = function(LEN,CH){
		var str=this;
		var ch = Boolean(CH)==false?" ":CH;
		while(str.length<LEN)
			str=ch+str;
		return str;
	};
	String.prototype.toggle = function(VALUE, OTHER){
		return this==VALUE?VALUE:OTHER;
	};
	String.prototype.unicode = function(){
		var str="", obj = this.split("");
		for(var i=obj.length-1; i>=0; i--)
			str="\\u{0}{1}".format(String(obj[i].charCodeAt(0).base(16)).leftpad(4,"0"),str);
		return str;
	};
	
})(window);
